home *** CD-ROM | disk | FTP | other *** search
- #include "AppTypes.h"
- #include "AppMacros.h"
- #include "CoreDialogUtilPr.h"
- #include "AppConstants.h"
-
- #include "NewDialogPr.h"
-
- static DialogRef InitNewDialog ( void );
-
- static char scale = kMiniHexSize; // what hex size is default?
- static Boolean drawIteration = false; // do we draw the iteration string or not?
- static Boolean alive[7] = {0, 1, 1, 0, 1, 1, 0}; // the default rule set
- static Boolean dead[7] = {0, 0, 0, 1, 1, 0, 0};
- static Boolean centerSeed = false; // do we only seed the center or perform a random seed?
-
- // doNewDialog - call to display and handle the New... dialog
- Boolean doNewDialog( GridDataPtr refCon, Boolean *seedCenter )
- {
- DialogRef theDlog;
- short itemHit = 0;
-
- if( !(theDlog = InitNewDialog()) )
- return( false );
-
- while( itemHit != iOK && itemHit != iCancel )
- {
- EventRecord theEvent;
- Boolean handled = false;
-
- WaitNextEvent( everyEvent, &theEvent, 0, nil );
- switch( theEvent.what )
- {
- case mouseDown:
- WindowRef theWindow;
- short where;
-
- where = FindWindow( theEvent.where, &theWindow );
-
- switch( where )
- {
- case inMenuBar:
- {
- short menuID, itemNumber;
- long menuResult;
-
- menuResult = MenuSelect( theEvent.where );
- menuID = MHiWord( menuResult );
- itemNumber = MLoWord( menuResult );
-
- switch( menuID )
- {
- case kAppleMenuID:
- {
- Str255 itemName;
-
- if( itemNumber == iAboutItem )
- Alert( kAboutScreenID, nil );
- else
- {
- GetItem( GetMHandle( kAppleMenuID ), itemNumber, itemName );
- OpenDeskAcc( itemName );
- }
- }
- break;
- case kFileMenuID:
- if( itemNumber == iQuitItem )
- {
- itemHit = iCancel;
- handled = true;
- }
- break;
- }
-
- HiliteMenu( 0 );
- }
- break;
- case inSysWindow:
- SystemClick( &theEvent, theWindow );
- break;
- case inDrag:
- SelectWindow( theWindow );
- DragWindow( theWindow, theEvent.where, &qd.screenBits.bounds );
- handled = true;
- break;
- case inGoAway:
- if( TrackGoAway( theWindow, theEvent.where ) )
- {
- itemHit = iCancel;
- handled = true;
- }
- break;
- }
- break;
- case keyDown:
- case autoKey:
- {
- char c = theEvent.message & charCodeMask;
- Rect box;
- short type;
- Handle item;
- long endTicks;
-
- if( (c == 'q' || c == 'Q') && theEvent.modifiers & cmdKey )
- {
- MenuKey( c );
- itemHit = iCancel;
- handled = true;
- HiliteMenu( 0 );
- }
- else if( c == 13 || c == 3 )
- {
- GetDItem( theDlog, iOK, &type, &item, &box );
-
- HiliteControl( (ControlHandle)item, true );
- Delay( 8, &endTicks );
- HiliteControl( (ControlHandle)item, false );
-
- itemHit = iOK;
- handled = true;
- }
- else if( (c == '.' && theEvent.modifiers & cmdKey) || (c == 0x1B) )
- {
- GetDItem( theDlog, iCancel, &type, &item, &box );
-
- HiliteControl( (ControlHandle)item, true );
- Delay( 8, &endTicks );
- HiliteControl( (ControlHandle)item, false );
-
- itemHit = iCancel;
- handled = true;
- }
- }
- break;
- }
- if( !handled && IsDialogEvent( &theEvent ) && DialogSelect( &theEvent, &theDlog, &itemHit ) )
- {
- switch( itemHit )
- {
- case i16by16:
- SetItemValue( theDlog, i16by16, true );
- SetItemValue( theDlog, i8by8, false );
- SetItemValue( theDlog, i4by4, false );
- break;
- case i8by8:
- SetItemValue( theDlog, i16by16, false );
- SetItemValue( theDlog, i8by8, true );
- SetItemValue( theDlog, i4by4, false );
- break;
- case i4by4:
- SetItemValue( theDlog, i16by16, false );
- SetItemValue( theDlog, i8by8, false );
- SetItemValue( theDlog, i4by4, true );
- break;
- case iIterationNo:
- case iSurvive0: case iSurvive1: case iSurvive2: case iSurvive3: case iSurvive4: case iSurvive5: case iSurvive6:
- case iRepro0: case iRepro1: case iRepro2: case iRepro3: case iRepro4: case iRepro5 : case iRepro6:
- InvertItem( theDlog, itemHit );
- break;
- case iSeedCentre:
- {
- ModalFilterUPP dialogFilter;
-
- dialogFilter = NewModalFilterProc( DLOGStandardProc );
- InvertItem( theDlog, iSeedCentre );
- if( GetItemValue( theDlog, iSeedCentre ) && !GetItemValue( theDlog, iRepro1 ) && (Alert( kSeedRuleID, dialogFilter ) == 1) )
- SetItemValue( theDlog, iRepro1, true );
- }
- break;
- }
- }
- }
-
- if( itemHit == iOK )
- {
- short count;
-
- if( GetItemValue( theDlog, i16by16 ) ) refCon->scale = kHexSize;
- else if( GetItemValue( theDlog, i8by8 ) ) refCon->scale = kMiniHexSize;
- else if( GetItemValue( theDlog, i4by4 ) ) refCon->scale = kTinyHexSize;
- scale = refCon->scale;
- refCon->drawIteration = GetItemValue( theDlog, iIterationNo );
- drawIteration = refCon->drawIteration;
- *seedCenter = GetItemValue( theDlog, iSeedCentre );
- centerSeed = *seedCenter;
- for( count = 0; count < 7; count++ )
- {
- refCon->alive[count] = GetItemValue( theDlog, iSurvive0 + count );
- alive[count] = refCon->alive[count];
- refCon->dead[count] = GetItemValue( theDlog, iRepro0 + count );
- dead[count] = refCon->dead[count];
- }
- }
-
- DisposeDialog( theDlog );
-
- return( itemHit == iOK );
- }
-
- // InitNewDialog - call to create the New... dialog
- static DialogRef InitNewDialog( void )
- {
- DialogRef theDlog;
- Rect globalRect;
- GrafPtr savePort;
- Point where;
- short scrLength, mBarHeight, count;
-
- if( !(theDlog = GetNewDialog( kNewDialogID, nil, (WindowRef)-1L )) )
- {
- Alert( kNotEnoughMemoryID, nil );
- return( nil );
- }
-
- GetPort( &savePort );
- SetPort( theDlog );
- globalRect = theDlog->portRect;
- LocalToGlobal( (Point *)(&globalRect) );
- LocalToGlobal( (Point *)(&globalRect) + 1 );
- SetPort( savePort );
- mBarHeight = GetMBarHeight();
-
- scrLength = qd.screenBits.bounds.right - qd.screenBits.bounds.left;
-
- where.v = mBarHeight + 60;
- where.h = (scrLength - (globalRect.right - globalRect.left)) / 2;
-
- MoveWindow( theDlog, where.h, where.v, false );
-
- switch( scale )
- {
- case kHexSize:
- SetItemValue( theDlog, i16by16, true );
- SetItemValue( theDlog, i8by8, false );
- SetItemValue( theDlog, i4by4, false );
- break;
- case kMiniHexSize:
- SetItemValue( theDlog, i16by16, false );
- SetItemValue( theDlog, i8by8, true );
- SetItemValue( theDlog, i4by4, false );
- break;
- case kTinyHexSize:
- SetItemValue( theDlog, i16by16, false );
- SetItemValue( theDlog, i8by8, false );
- SetItemValue( theDlog, i4by4, true );
- break;
- }
- SetItemValue( theDlog, iSeedCentre, centerSeed );
- SetItemValue( theDlog, iIterationNo, drawIteration );
- for( count = 0; count < 7; count++ )
- {
- SetItemValue( theDlog, iSurvive0 + count, alive[count] );
- SetItemValue( theDlog, iRepro0 + count, dead[count] );
- }
-
- SetItemHandle( theDlog, iOKOutline, pBWButtonOutlineProc );
-
- ShowWindow( theDlog );
-
- return( theDlog );
- }